package com.golookon.managed;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.golookon.dao.StateCityDao;

@Component("stateCityManager")
@Scope("session")
public class StateCityManager {
	
	public StateCityManager() {

	}

	@Inject 
	StateCityDao stateCityDao;
	
	private List<String> states;
	private List<String> cities;
	private UserManager userManager;
	

	public UserManager getUserManager() {
		return userManager;
	}

	@Autowired
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}
	
	//private String state = userManager.getPotentialUser().getState();

	@PostConstruct
	public void init() {
		loadStates();
	}
	
	public void loadStates(){
		states = stateCityDao.getAllStates();
		cities = new ArrayList<String>();
	}
	
	 public void handleStateChange() {  
	        if(userManager.getPotentialUser().getState() !=null && !userManager.getPotentialUser().getState().equals(""))  
	            cities = stateCityDao.getCitiesByState(userManager.getPotentialUser().getState());  
	        else  
	            cities = new ArrayList<String>();  
	    }  
	

	public StateCityDao getStateCityDao() {
		return stateCityDao;
	}

	public void setStateCityDao(StateCityDao stateCityDao) {
		this.stateCityDao = stateCityDao;
	}

	public List<String> getStates() {
		return states;
	}

	public void setStates(List<String> states) {
		this.states = states;
	}

	public List<String> getCities() {
		return cities;
	}

	public void setCities(List<String> cities) {
		this.cities = cities;
	}


}
